//
//  EventViewCell.m
//  investevent
//
//  Created by jiangshao on 16/3/9.
//  Copyright © 2016年 com.scj.investevent. All rights reserved.
//

#import "EventViewCell.h"

@implementation EventViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

-(void)setContent:(NSDictionary *)data{
    
    @try {
        for (UIView *view in titleView.subviews) {
            [view removeFromSuperview];
        }
        
        NSString *date=[data objectForKey:@"date"];
        NSString *week=[data objectForKey:@"week"];
        dateLabel.text=[NSString stringWithFormat:@"%@(%@)",date,week ];
        
        NSArray *events=[data objectForKey:@"events"];
        NSArray *concept=[data objectForKey:@"concept"];
        
        int originalheight=0;
        for (int i=0;i<events.count;i++) {
            UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, originalheight, screenviewwidth, 0)];
            UILabel *labelId=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
            UILabel *textlabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 8, screenviewwidth-16, 0)];
            [view addSubview:labelId];
            [view addSubview:textlabel];
            [titleView addSubview:view];
            labelId.text=@"";
            
            NSArray *eventitems=events[i];
            NSString *event=eventitems[0];
            
            textlabel.text=[NSString stringWithFormat:@"股市事件:%@",event];
            textlabel.font=[UIFont systemFontOfSize:16];
            textlabel.textColor=[UIColor darkGrayColor];
            
            NSArray *conceptitems=concept[i];
            if (conceptitems.count>0) {
                labelId.text=[conceptitems[0]objectForKey:@"code"];
                NSString *conceptitem=[conceptitems[0]objectForKey:@"name"];
                textlabel.text=[NSString stringWithFormat:@"股市事件:%@\n影响板块:%@",event,conceptitem];
            }
            [textlabel resizeHeight];
            originalheight=originalheight+textlabel.frame.size.height+16;
        }
        titleViewHeight.constant=originalheight;

    }
    @catch (NSException *exception) {
        NSLog(@"哈哈");
    }
    @finally {
        
    }
    }

@end
